﻿Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared


Public Class Form1
    '*** Crystal Reports Connection Object
    Private _CRConnectionInfo As ConnectionInfo
    '*** Loads report from file
    Private _kfxAdvancedReport As ReportDocument

    Private _currentReportName As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = "C:\Program Files\Kofax\CaptureSS\ServLib\Bin\Advanced Reports\Oracle\US-CRA.01-ClassificationVsReview.rpt"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Create connection
        _CRConnectionInfo = New ConnectionInfo()

        '*** Set the Connection Properties
        With _CRConnectionInfo
            .DatabaseName = "Statistics"
            .ServerName = "kc"
            .UserID = "Statistics"
            .Password = "Statistics"
        End With

        'Load rpt file
        _currentReportName = TextBox1.Text
        _kfxAdvancedReport = New ReportDocument()
        _kfxAdvancedReport.Load(_currentReportName)

        'Apply connection
        Dim KfxAdvRepTables As Tables = _kfxAdvancedReport.Database.Tables
        '*** Iterate through the tables and set the appropriate properties
        For Each KfxAdvRepTable As CrystalDecisions.CrystalReports.Engine.Table In KfxAdvRepTables
            Dim KfxAdvRepTableLogonInfo As TableLogOnInfo = KfxAdvRepTable.LogOnInfo
            'KfxAdvRepTableLogonInfo.ConnectionInfo = _CRConnectionInfo
            KfxAdvRepTableLogonInfo.ConnectionInfo.ServerName = "kc"
            KfxAdvRepTableLogonInfo.ConnectionInfo.DatabaseName = "Statistics"
            KfxAdvRepTableLogonInfo.ConnectionInfo.UserID = "Statistics"
            KfxAdvRepTableLogonInfo.ConnectionInfo.Password = "Statistics"
            KfxAdvRepTableLogonInfo.TableName = KfxAdvRepTable.Name
            KfxAdvRepTable.ApplyLogOnInfo(KfxAdvRepTableLogonInfo)
        Next KfxAdvRepTable

        'Show report
        Try
            Dim repContext As ReportPageRequestContext = New ReportPageRequestContext
            _kfxAdvancedReport.FormatEngine.GetLastPageNumber(repContext)

        Catch ex As Exception

        End Try

        CrystalReportViewer1.ReportSource = _kfxAdvancedReport

    End Sub
End Class
